<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{$meta}
<link type="text/css" rel="stylesheet" href="{$css_path}/global.css" />
<link type="text/css" rel="stylesheet" href="{$css_path}/style.css" />
</head><body>
<!--头部--> 
{include file="top.html"}
{include file="header.html"} 
<!--登录-->
<div id="main">
  <div id="q2a_ask_left">
   {include file="message.html"}
    <form id='question_form' action="{$site_url}question/ask" method="post">
    <input type='hidden' id='question_category' name='category_id' value=''/>
        <table>
          <tr>
            <td width="12%" class="q2a_title">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题：</td>
            <td><input type="text"  name="name" class="text big" id="name"/></td>
          </tr>
          <tr>
            <td class="q2a_title">分 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;类：</td>
            <td>
            <select id="category_select" >
            	<option value="">选择分类</option> 
                {foreach from=$category_list item=list}
                <option value="{$list.id}">{$list.value}</option>
                {/foreach} 
            </select>
            <div id="sub_category">
           
            </div>
            </td>
          </tr>
           <tr>
            <td width="12%" class="q2a_title">积&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分：</td>
            <td><input type="text"  name="points" class="text small" id="points"/>
            	<p>您目前积分为:(<a href="{$site_url}user/account/amount" style="color:#1085E4" target="_blank">{$user_account}</a>)</p>
            </td>
          </tr>
            <tr>
            <td width="12%" class="q2a_title">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述：</td>
            <td><textarea  style="height:90px;"  name="content" id="content"></textarea>
            
            	<p>请详细描述,方便他人回复</p>
            </td>
          </tr>
          
              <tr>
                  <td class='q2a_title'>标签：</td>
                  <td>
                      <input  id='tag' class='text big' type='text' name='tag' size="60" />
                      <span id="load_tag" style="color:red;"></span>
                      <p>输入正确的标签,别人更容易找到！多个标签请用空格分开！</p>
                  </td>
              </tr>
          <tr>
            <td class='q2a_title'> 验 证 码 ：</td>
            <td><input type='text' id='captcha' name='captcha' class='text'/> 
            <div>{$captcha}<span><a href="javascript:reloadcode();">换另外一个图</a></span></div></td>
          </tr>
           <tr>
            <td colspan="3" align="center"> <input type="submit"  class="btnzc" value="发&nbsp;&nbsp;布"/></td>
          </tr>
        </table>
        
      </form>
      <div class="clear"></div>
  </div>
  <div id="q2a_ask_right">
    <div id="question_tip">
    	<h2>提问规则</h2>
    	<ol>
    		<li>清晰说明问题</li>
			<li>关键词非常重要,方便通过标签找到问题</li>
    		<li>问题的内容尽量的描述清晰</li>
    		
    	</ol>
	</div>
    <img src="{$images_path}/right_img.png">
  </div>
  <div class="clear"></div>
</div>
<script type="text/javascript" src="{$js_path}/message.js"></script> 
<script type="text/javascript" src="{$js_path}/jquery.validate.js"></script> 
<script>
   function reloadcode(){
        document.getElementById('captcha_change').src = '{$site_url}captcha/default?r='+Math.random(); ;
    } 
function change_id(id){
	$('a.qa_type').removeClass('selected');
		$('#qa_type_'+id).addClass('selected');
		$('#question_category').val($('#qa_type_'+id).attr('type'));
		return ;

}
$(function(){
	
	 $("#question_form").validate({
		  errorElement:"p",
	  rules: {
		  name: {
			  required: true,
			  maxlength:50
		  },
		  content:{
			  required: true,
			  minlength: 20
		  },
		  points:{
			  number:true,
			  max:{$user_account}
		  },
		  captcha:"required"
	  },
	  messages: {
		  name: {
			  required: "标题不能为空!",
			  maxlength: "标题必须小于50位!"
		  },
		  content:{
			  required:'内容不能为空',
			  minlength:'内容必须大于20位'
		  },
		  points:{
			  number:'积分必须为数字',
			  max:"积分最多为{$user_account.points}"
		  },
		  captcha:"验证码不能为空"
	  }
  });
	
	
	
	$('#name').focusout(function() {
		if($('#tag').val() ==''){
			$.ajax({
				url:"{$site_url}ajax/splitword",
				type:'post',
				dataType:'text',
				data:'word='+$(this).val(),
				beforeSend:function(XMLHttpRequest){
					$("#load_tag").text("正在加载中...");
				},
				success:function(data){
					$('#tag').val(data);
					$("#load_tag").text("");
				}
			});
		}
	});


	$('#category_select').change(function(){
		var param = "parent_id="+$(this).val()+"&type=q2a"; 
		if($(this).val() != ''){
			
			$.ajax({
			type:'POST',
			url:'{$site_url}ajax/get_sub_category',
			data:param,
			dataType:'json',
			success:function(data){
				if(data == 0 ){
						$('#sub_category').html('暂无'); 	
				 } else{
					var html = '';
					$.each(data, function(i, n){
						html =html + "<a class='qa_type' id='qa_type_"+n.id+"' title='"+n.value+"' type='"+n.id+"' href='javascript:change_id("+n.id+")'>"+n.value+"</a> ";
					});
				 
					$('#sub_category').html(html);
				}
			   } 
				});
		}
	});
})
</script>
{include file="footer.html"}
</body>
</html>
